<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>订舱业务管理</title>
    <s:head/>

    <!-- 自定义style -->
    <style>
        .dataTB {
            width: 100%;
            border: 1px solid #ccc;
            line-height: 30px;
        }

        td.dataTD {
            font-weight: bold;
        }
    </style>
    <!-- 自定义style -->
    <!-- 自定义script -->
    <script type="text/javascript">
        var bookingDataValue = "";

        var bookingId = "${booking.id}";

        var shipperFormSetting = {
            title: "出口公司：",
            columns: [{
                name: "booking.shipper.id",
                label: "id",
                hidden: true
            }, {
                name: "booking.shipper.company",
                label: "公司名称",
                readonly: true
            }, {
                name: "booking.shipper.name",
                label: "联系人",
                readonly: true
            }, {
                name: "booking.shipper.phone",
                label: "联系电话",
                readonly: true
            }, {
                name: "booking.shipper.address",
                label: "联系地址",
                readonly: true
            }],
            form: {
                'data': function () {
                    return bookingDataValue;
                }
            }
        };

        var consigneeFormSetting = {
            title: "收货公司：",
            columns: [{
                name: "booking.consignee.id",
                label: "id",
                hidden: true
            }, {
                name: "booking.consignee.company",
                label: "公司名称",
                readonly: true
            }, {
                name: "booking.consignee.name",
                label: "联系人",
                readonly: true
            }, {
                name: "booking.consignee.phone",
                label: "联系电话",
                readonly: true
            }, {
                name: "booking.consignee.address",
                label: "联系地址",
                readonly: true
            }],
            form: {
                'data': function () {
                    return bookingDataValue;
                }
            }
        };

        var baseInfoFormSetting = {
            title: "托运信息：",
            columns: [{
                name: "booking.supCompany.id",
                label: "业务代理人",
                validate: 'validate[required]',
                type: "dropdown",
                dropdownType: "ajax",
                url: "../base/dropdown-supComByNameType?com_type=CC&sup_type=F",
                minLength: 0
            }, {
                name: "booking.shipping.id",
                label: "大船公司",
                type: "dropdown",
                dropdownType: "ajax",
                url: "../base/dropdown-supComByNameType?com_type=SC",
                minLength: 1
            }, {
                name: "booking.businessType",
                label: "业务类型",
                type: "dropdown",
                dropdownType: "ajax",
                url: "../base/dropdown-bookingBusinessType",
                minLength: 0
            }, {
                name: "booking.stPort",
                label: "起运港"
            }, {
                name: "booking.arPort",
                label: "目的港"
            }, {
                name: "booking.shipDate",
                label: "船期要求",
// 			type: "date"
            }, {
                name: "booking.price",
                label: "合作价格"
            }, {
                name: "booking.remark",
                label: "备注",
                type: "textarea"
            }],
            form: {
                'data': function () {
                    if (bookingDataValue.booking.supCompany != null) {
                        var dropdownName = $.mrdForm.getDropDwonLabelName("booking.supCompany.id");
                        bookingDataValue[dropdownName] = bookingDataValue.booking.supCompany.name;
                    }
                    if (bookingDataValue.booking.shipping != null) {
                        var dropdownName = $.mrdForm.getDropDwonLabelName("booking.shipping.id");
                        bookingDataValue[dropdownName] = bookingDataValue.booking.shipping.name;
                    }
                    if (bookingDataValue.booking != null) {
                        var dropdownName = $.mrdForm.getDropDwonLabelName("booking.businessType");
                        bookingDataValue[dropdownName] = bookingDataValue.businessDto.bookingBusinessType;
                    }
                    return bookingDataValue;
                }
            }
        };

        var formSetting = {
            title: "订舱业务管理",
            module: 'save',
            fieldsets: [shipperFormSetting, consigneeFormSetting, baseInfoFormSetting],
            columns: [{
                name: "booking.id",
                label: "id",
                hidden: true
            }],
            form: {
                'url': 'booking-tsaveOrUpdate',
                'data': function () {
                    var id = "${booking.id}";
                    if (id) {
                        var dataValue = "";
                        $.ajax({
                            url: "booking-find?booking.id=" + id,
                            async: false,
                            success: function (data) {
                                dataValue = data;
                            }
                        });
                        bookingDataValue = dataValue;
                        return dataValue;
                    } else {
                        return null;
                    }
                },
                afterAjaxSuccess: function (responseText, statusText, xhr, $form) {
                    if ($.parseJSON(responseText.msg).state == 1) {
                        //window.location.href="booking-main";
                    }
                }
            },
            buttons: {
                reset: false,
                save: false,
                custom: [{
                    id: "updatebtn1",
                    value: "保存数据",
                    click: function () {
                    }
                }, {
                    id: "updatebtn2",
                    value: "保存并提交业务",
                    click: function () {
                    }
                }]
            },
            grid: {
                id: "bookingGoodsDataGrid",
                title: "商品信息：",
                multiselect: true,
                url: "booking-findGoodsList?booking.id=" + bookingId,
                colModel: [{
                    index: "ID",
                    name: "id",
                    hidden: true
                }, {
                    index: "name",
                    name: "name",
                    label: "商品名称",
                    sortable: false
                }, {
                    index: "gweight",
                    name: "gweight",
                    label: "毛重/KG",
                    sortable: false
                }, {
                    index: "nweight",
                    name: "nweight",
                    label: "净重/KG",
                    sortable: false
                }, {
                    index: "volume",
                    name: "volume",
                    label: "体积/立方米",
                    sortable: false
                }, {
                    index: "ctNumType",
                    name: "ctNumType",
                    label: "所需柜量",
                    sortable: false
                }],
                jsonReader: {
                    root: "goodses"
                }
            }
        };
        $(function () {
            $("#formtable").mrdForm(formSetting);
        });
    </script>

</head>
<body>
<div style="width: 100%">
    <div id="formtable">
    </div>
</div>
</body>
</html>
